package com.atguigu.staservice.scheduled;

import com.atguigu.staservice.service.StatisticsDailyService;
import com.atguigu.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @author ：MJS
 * @date ：Created in 2021/4/20  15:26
 * @description：TODO
 */
public class ScheduledTask {
    @Autowired
    private StatisticsDailyService dailyService;
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void testTask(){
//        System.out.println("执行任务");
//    }

    //每天凌晨一点执行生成统计数据调度
    @Scheduled(cron = "0 0 1 * * ?")
    public void createTask(){
        //获取前一天的数据
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        dailyService.createStaDaily(day);
    }
}
